﻿<UserControl xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"  x:Class="BizControl.Presentation.ActivityEditModule.Views.ActivityEditView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:controls="clr-namespace:BizControl.Presentation.Infrastructure.Controls;assembly=BizControl.Presentation.Infrastructure"
             xmlns:rating="clr-namespace:BizControl.Presentation.Infrastructure.Controls.StarRating;assembly=BizControl.Presentation.Infrastructure"
             xmlns:csla="clr-namespace:Csla.Xaml;assembly=Csla.Xaml"
             xmlns:res="clr-namespace:BizControl.Presentation.Infrastructure.Properties;assembly=BizControl.Presentation.Infrastructure"
             xmlns:views="clr-namespace:BizControl.Presentation.ActivityEditModule.Views"
             xmlns:biz="clr-namespace:BizControl.Library;assembly=BizControl.Library"
             xmlns:converters="clr-namespace:BizControl.Presentation.ActivityEditModule.Converters"
             x:Name="ActivityEditControl">

    <UserControl.Resources>
        <csla:IdentityConverter x:Key="IdentityConverter" />
        <converters:ActivityRatingToTextConverter x:Key="ActivityRatingToTextConverter" />
        <converters:ActivityQualityToDecimalConverter x:Key="ActivityQualityToDecimalConverter" />
    </UserControl.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="30" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <ToolBar>
            <!-- BeginRefresh and BeginFetch -->
            <!--<csla:BusyAnimation Name="BusyAnimation" Foreground="Wheat" IsRunning="{Binding Path=Model.IsBusy}" />-->
            <Button x:Name="SaveButton" HorizontalAlignment="Left" 
                    VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"
                    Width="25" Height="25" ToolTip="Сохранить"
                    IsEnabled="{Binding CanSave}"
                    Template="{StaticResource OkButtonTemplate}">
            </Button>
            <csla:TriggerAction TargetControl="{Binding ElementName=SaveButton}" MethodName="Save"/>
            <Button HorizontalAlignment="Right" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"
                    Width="25" Height="25" ToolTip="Закрыть"
                    Command="{Binding Path=CloseCommand}"
                    Template="{StaticResource CancelButtonTemplate}">
            </Button>
        </ToolBar>
        <TabControl x:Name="ActivityTabControl" Grid.Row="1" Margin="2,2,8,8"
                    HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
                    ItemContainerStyle="{StaticResource CustomTabItemStyle}">
            <TabItem x:Name="ActivityTab">
                <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                    <StackPanel>
                        <Grid Margin="2">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="350" />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <StackPanel>
                                <TextBlock Text="Описание задачи:" Margin="2" FontSize="10pt" HorizontalAlignment="Left" VerticalAlignment="Center" />
                                <StackPanel Orientation="Horizontal">
                                    <TextBox Width="300" Height="200" Margin="2" VerticalAlignment="Center" HorizontalAlignment="Stretch"
                                             FontSize="10pt" FontWeight="Bold" 
                                             TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Auto"
                                             Text="{Binding Path=Model.Description, UpdateSourceTrigger=PropertyChanged}" />
                                    <csla:PropertyStatus Grid.Column="1" Margin="2" DataContext="{Binding Model}" Property="{Binding Path=Description}"/>
                                </StackPanel>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="Автор:" Margin="2" FontSize="10pt" HorizontalAlignment="Left" VerticalAlignment="Center" />
                                    <Border Margin="5" HorizontalAlignment="Left" BorderThickness="1" BorderBrush="Black" CornerRadius="2">
                                        <controls:CurrentUserImageOnlyControl DataContext="{Binding Path=Model.CreatedBy}" />
                                    </Border>
                                    <StackPanel VerticalAlignment="Center">
                                        <TextBlock Visibility="{Binding Path=Model.IsCompleted, Converter={StaticResource BoolFalseToVisibilityConverter}}"
                                                   HorizontalAlignment="Right" VerticalAlignment="Center" Margin="80,2,2,2">
                                            <Hyperlink Command="{Binding Path=SetCompleteCommand}">
                                                <TextBlock Text="Завершить задачу" />
                                            </Hyperlink>
                                        </TextBlock>
                                        <StackPanel Orientation="Horizontal" Visibility="{Binding Path=Model.IsCompleted, Converter={StaticResource BoolToVisibilityConverter}}">
                                            <TextBlock Text="Оценка выполнения:" Margin="2" HorizontalAlignment="Left" VerticalAlignment="Center" />
                                            <rating:StarRatingControl x:Name="activityRating" HorizontalAlignment="Center" VerticalAlignment="Center"
                                                                      NumberOfStars="3" Maximum="3" Minimum="1" Step="1"
                                                                      StarForegroundColor="Yellow"
                                                                      Value="{Binding Path=Model.Quality, Mode=TwoWay, Converter={StaticResource ActivityQualityToDecimalConverter}}">
                                                <rating:StarRatingControl.ToolTip>
                                                    <MultiBinding Converter="{StaticResource ActivityRatingToTextConverter}">
                                                        <Binding ElementName="activityRating" Path="Value"/>
                                                        <Binding ElementName="activityRating" Path="HoverValue"/>
                                                        <Binding ElementName="activityRating" Path="IsHovering"/>
                                                    </MultiBinding>
                                                </rating:StarRatingControl.ToolTip>
                                            </rating:StarRatingControl>
                                        </StackPanel>
                                    </StackPanel>
                                </StackPanel>
                            </StackPanel>

                            <Grid Margin="2" Grid.Column="1">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="150" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                </Grid.RowDefinitions>

                                <TextBlock Grid.Row="1" Grid.Column="0"
                                           Text="Дата начала задачи:" Margin="2" FontSize="10pt" HorizontalAlignment="Left" VerticalAlignment="Center" />
                                <StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal">

                                    <DatePicker Width="200" Margin="2" FontSize="10pt" FontWeight="Bold" 
                                                VerticalAlignment="Center" HorizontalAlignment="Left" SelectedDateFormat="Long"
                                                SelectedDate="{Binding Path=Model.StartDate, UpdateSourceTrigger=PropertyChanged}" />
                                    <csla:PropertyStatus Margin="2" DataContext="{Binding Model}" Property="{Binding Path=StartDate}"/>
                                </StackPanel>
                                <Border Grid.Row="1" BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderLightBrush}" />

                                <TextBlock Grid.Row="2" Grid.Column="0"
                                           Text="К сроку:" Margin="2" FontSize="10pt" HorizontalAlignment="Left" VerticalAlignment="Center" />
                                <StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal">
                                    <DatePicker Width="200" Margin="2" FontSize="10pt" FontWeight="Bold" 
                                                VerticalAlignment="Center" HorizontalAlignment="Left" SelectedDateFormat="Long"
                                                SelectedDate="{Binding Path=Model.DueDate, UpdateSourceTrigger=PropertyChanged}" />
                                    <csla:PropertyStatus Margin="2" DataContext="{Binding Model}" Property="{Binding Path=DueDate}"/>
                                </StackPanel>
                                <Border Grid.Row="2" BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderLightBrush}" />

                                <TextBlock Grid.Row="3" Grid.Column="0"
                                           Text="Ответственный участник:" Margin="2" FontSize="10pt" TextWrapping="Wrap"
                                           HorizontalAlignment="Left" VerticalAlignment="Center" />
                                <StackPanel Grid.Row="3" Grid.Column="1">
                                    <ComboBox Width="150" Height="60"
                                              IsEnabled="{Binding Path=Model.CanChangeResponsiblePerson}"
                                              VerticalAlignment="Center" HorizontalAlignment="Left"
                                              ItemsSource="{Binding Path=PeopleParticipants}"
                                              SelectedValue="{Binding Path=Model.ResponsiblePerson, Mode=TwoWay}">
                                        <ComboBox.ItemTemplate>
                                            <DataTemplate>
                                                <Border Margin="2" BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderLightBrush}">
                                                    <controls:CurrentUserControl FontSize="8" />
                                                </Border>
                                            </DataTemplate>
                                        </ComboBox.ItemTemplate>
                                    </ComboBox>
                                    <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Margin="2">
                                        <Hyperlink Click="ManageParticipants_Click">
                                            <TextBlock Text="Управление участниками..." />
                                        </Hyperlink>
                                    </TextBlock>
                                </StackPanel>
                                <Border Grid.Row="3" BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderLightBrush}" />

                                <TextBlock Grid.Row="4" Grid.Column="0" 
                                           Text="Приоритет:" Margin="2" FontSize="10pt" HorizontalAlignment="Left" VerticalAlignment="Center" />
                                <ComboBox Grid.Row="4" Grid.Column="1"
                                          Width="200" Height="25" FontSize="10pt" FontWeight="Bold" Margin="2"
                                          VerticalAlignment="Center" HorizontalAlignment="Left"
                                          ItemsSource="{Binding Path=Priorities}"
                                          DisplayMemberPath="Key"
                                          SelectedValuePath="Value"
                                          SelectedValue="{Binding Path=Model.Priority, Mode=TwoWay}"/>
                                <Border Grid.Row="4" BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderLightBrush}" />

                                <TextBlock Grid.Row="5" Grid.Column="0" 
                                           Text="Категория:" Margin="2" FontSize="10pt" HorizontalAlignment="Left" VerticalAlignment="Center" />
                                <ComboBox Grid.Row="5" Grid.Column="1"
                                          Width="200" Height="25" FontSize="10pt" FontWeight="Bold" Margin="2"
                                          VerticalAlignment="Center" HorizontalAlignment="Left"
                                          ItemsSource="{Binding Path=Categories}"
                                          DisplayMemberPath="Name"
                                          SelectedValue="{Binding Path=SelectedCategory, Mode=TwoWay}"/>

                                <Border Grid.Row="5" BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderLightBrush}" />

                                <TextBlock Grid.Row="6" Grid.Column="0"
                                           Text="Прогресс задачи:" Margin="2" FontSize="10pt" HorizontalAlignment="Left" VerticalAlignment="Center" />
                                <ProgressBar Grid.Row="6" Grid.Column="1"
                                             Style="{StaticResource ProgressBarWithText}" Height="25" Width="200" Margin="2"
                                             VerticalAlignment="Center" HorizontalAlignment="Left"
                                             Value="{Binding Path=Model.Progress, Mode=OneWay}" />
                                <Border Grid.Row="6" BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderLightBrush}" />
                            </Grid>
                        </Grid>
                        <Border BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderLightBrush}" />
                        <GroupBox Header="Работы" Margin="2">
                            <views:MarksView Margin="5" />
                        </GroupBox>
                    </StackPanel>
                </ScrollViewer>
            </TabItem>
            <TabItem x:Name="ParticipantsTab" DataContext="{Binding ParticipantsVM}">
                <views:ParticipantsView />
            </TabItem>
            <TabItem x:Name="ConditionsTab" DataContext="{Binding MarksConditionsVM}" 
                     Visibility="{Binding ElementName=ActivityEditControl, Path=DataContext.Model.HasMarks, Converter={StaticResource BoolToVisibilityConverter}}">
                <views:MarksConditionsView x:Name="MarksConditionsViewControl" />
            </TabItem>
            <TabItem DataContext="{Binding CommentsVM}">
                <views:CommentsView />
            </TabItem>
            <TabItem DataContext="{Binding DependentActivitiesVM}">
                <views:DependentActivitiesView />
            </TabItem>
        </TabControl>
    </Grid>
</UserControl>
